﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public class UserData_41_TestConfirm : UserData
	{
		#region private member variables

		private readonly bool _timerVariantFlag;
		private readonly eAddressExtension_2 _addressExtension2;
		private readonly UInt16 _minNextTestMessage;

		#endregion private member variables

		#region constructor

		public UserData_41_TestConfirm()
			: base(UserData.UserData41TestConfirm)
		{
			_timerVariantFlag = false;
		}

		/// <summary>
		/// Variant with time interval of expected next test message
		/// </summary>
		public UserData_41_TestConfirm(eAddressExtension_2 addressExtension2, UInt16 minNextTestMessage)
			: base(UserData.UserData41TestConfirm)
		{
			_timerVariantFlag = true;
			_addressExtension2 = addressExtension2;
			_minNextTestMessage = minNextTestMessage;
		}

		#endregion constructor

		#region getters

		public bool TimerIncluded { get { return _timerVariantFlag; } }
		public eAddressExtension_2 AddressExtension { get { return _addressExtension2; } }
		public UInt16 MinNextTestMessage { get { return _minNextTestMessage; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();
			hashCode ^= (byte) AddressExtension;
			hashCode ^= (byte) MinNextTestMessage / 256;
			hashCode ^= (byte) MinNextTestMessage % 256;

			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());

			stringBuilder.Append(", ");

			stringBuilder.Append("AddressExtension='");
			stringBuilder.Append(AddressExtension);
			stringBuilder.Append("'");

			stringBuilder.Append(", ");

			stringBuilder.Append("MinNextTestMessage='");
			stringBuilder.Append(MinNextTestMessage);
			stringBuilder.Append("'");

			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				UserData_41_TestConfirm userData2Compare = obj as UserData_41_TestConfirm;
				return EqualsProperties(userData2Compare);
			}

			return false;
		}

		internal bool EqualsProperties(UserData_41_TestConfirm userData2Compare)
		{
			if (base.EqualsProperties(userData2Compare))
			{
				if (AddressExtension == userData2Compare.AddressExtension)
				{
					return (MinNextTestMessage == userData2Compare.MinNextTestMessage);
				}

				return false;
			}

			return false;
		}

		#endregion ToString, Equals, GetHashCode
	}
}
